package com.honghe.controller;

import com.honghe.dto.DepartmentDTO;
import com.honghe.dto.DepartmentPageDTO;
import com.honghe.entity.Department;
import com.honghe.result.PageResult;
import com.honghe.result.Result;
import com.honghe.service.DepartmentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/doctor/department")
@RestController
@Slf4j
@Tag(name = "部门管理")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    @GetMapping("/page")
    @Operation(summary = "分页查询")
    public Result<PageResult> pageQurey(DepartmentPageDTO departmentPageDTO){
        PageResult pageResult = departmentService.pageQuery(departmentPageDTO);
        return Result.success(pageResult);
    }

    @PutMapping("/update")
    @Operation(summary = "修改部门")
    public Result<String> update(@RequestBody DepartmentDTO departmentDTO){
        departmentService.update(departmentDTO);
        return Result.success();
    }

    @PostMapping("/add")
    @Operation(summary = "添加部门")
    public Result<String> insert(@RequestBody DepartmentDTO departmentDTO){
        departmentService.insert(departmentDTO);
        return Result.success();
    }
    @DeleteMapping("/delete")
    @Operation(summary = "删除部门")
    public Result<String> delete(Long id){
        departmentService.delete(id);
        return Result.success();
    }
    @GetMapping("/get/{id}")
    @Operation(summary = "根据id查询部门")
    public Result<Department> getById(@PathVariable Long id){
        Department department = departmentService.getById(id);
        return Result.success(department);
    }
}
